import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import HomeView from '../views/HomeView.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '',
    redirect: {
      name: 'home'
    }
  },
  {
    path: '/home',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
    children: [
      {
        path: '',
        redirect: {
          name: 'about1'
        }
      },
      {
        path: '/about',
        name: 'about1',
        component: () => import(/* webpackChunkName: "about1" */ '../views/AboutView.vue')
      }
    ]
  },
  {
    path: '/finsh',
    name: 'finsh',
    component: () => import(/* webpackChunkName: "finsh" */ '../views/finsh.vue')
  },
  {
    path: '/delete',
    name: 'delete',
    component: () => import(/* webpackChunkName: "delete" */ '../views/DeleteList.vue')
  },
  {
    path: '/edit',
    name: 'edit',
    component: () => import(/* webpackChunkName: "edit" */ '../views/edit.vue'),
    props: true,
    beforeEnter: (to, from, next) => {
      if (from.name === 'home') {
        next()
      } else {
        next('./home')
      }
    }
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  linkExactActiveClass: 'active'
})

export default router
